package com.dhl.rabbitmq.seven;

import com.dhl.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 */
public class EmitLogTopic {

    public static final String EXCHANGE_NAME = "topic_log";

    public static void main(String[] args) throws Exception {
        // 1.获取信道
        Channel channel = RabbitUtils.getChannel();
        // 2.获取交换
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

        HashMap<String, String> hashMap = new HashMap<>(8);
        hashMap.put("quick.orange.rabbit","被队列 Q1Q2 接收到");
        hashMap.put("lazy.orange.elephant","被队列 Q1Q2 接收到");
        hashMap.put("quick.orange.fox","被队列 Q1 接收到");
        hashMap.put("lazy.brown.fox","被队列 Q2 接收到");
        hashMap.put("lazy.pink.rabbit","虽然满足两个绑定但只被队列 Q2 接收一次");
        hashMap.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        hashMap.put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        hashMap.put("lazy.orange.male.rabbit ","是四个单词但匹配 Q2");

        for (Map.Entry<String, String> stringStringEntry : hashMap.entrySet()) {
            String routing = stringStringEntry.getKey();
            // 3.发送信息
            String message =routing + hashMap.get(routing);
            channel.basicPublish(EXCHANGE_NAME, routing, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes(StandardCharsets.UTF_8));
        }

    }
}
